<?php

//$db_host = "192.168.30.182";				// Database host
//$db_user = "root"; 					// Database username
//$db_pass = "123abc!@#";						// Database password
//$db_name = "db_study";

$db_host = "localhost";				// Database host
$db_user = "root"; 					// Database username
//$db_pass = "P@ssword123";						// Database password
$db_pass ="";
$db_name = "wheelhouse";

$con=mysql_connect($db_host,$db_user,$db_pass);
if(!$con)
{
	die ("Failed to connect to database" .mysql_error());
}
$selected_db=mysql_select_db($db_name,$con);
if(!$selected_db)
{
	echo('Could not connect to desired databse');
}

function GetFirstItemFromDB($query)
{
    $result = mysql_query($query);
    @$num_rows = mysql_num_rows($result);
    if($num_rows == 0) {
       return 0;
    } else {
        $row = mysql_fetch_array($result);
        return $row;
    }
}

///Get logo from DB
///params: $page: page id
///params: $location: 0 for left, 1 for right
///parasm: $alt: alternative string when img can not be displayed
function GetLogo($page, $location, $alt,$width,$height)
{
    $query = "Select * from logo WHERE page_id = '".$page."' AND location='".$location."'
                AND flag='1' AND is_deleted = '0'";
    $db_item = GetFirstItemFromDB($query);
    $path = $db_item['path'];
	if(!$width || !$height){
    	return "<img alt=\"".$alt."\" src=\"".$path."\"/>";
	}else{
		return "<img style='width:". $width ."px; height:". $height ."px;' alt=\"".$alt."\" src=\"".$path."\"/>";
	}
}
/*
 * Function: mysql_fetch_full_result_array
 * chuyển toàn bộ array lấy từ DB sang chuỗi.
 * Author: Viet
 */

function mysql_fetch_full_result_array($result)
{
    $table_result=array();
    $r=0;
    $str="";
    while($row = mysql_fetch_assoc($result)){
        $arr_row=array();
        $c=0;
        $str.= "{";
        while ($c < mysql_num_fields($result)) {       
            $col = mysql_fetch_field($result, $c);   
//            $arr_row[$col -> name] = $row[$col -> name];        
          	$str .= $row[$col -> name] . "#";   
            $c++;
        }
        $str = chop($str,"#");
        $str .= "}#";   
//        $table_result[$r] = $arr_row;
        $r++;
    }   
    $str= chop($str,"#");
//	$str = str_replace(".-", "<br/>", $str);

    return $str;
}
?>